/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = t_cics_init_packet.c                               */
/*  NOTE      =                                                    */
/*  DATE      = 2016/02/19 by songbb                               */
/*******************************************************************/

#include <CUnit/Basic.h>

#include "frcomm.h"
#include "frmem.h"

#include <cics/config.h>
#include <cics/cics_core.h>
#include <cics/cics_packet.h>

extern void __cics_destroy_packet(L7_cics_packet **pp_st_cics_packet);

static int __suite_init(void)
{
    return 0;
}

static int __suite_cleanup(void)
{
    return 0;
}

static void __case1(void)
{
    L7_cics_packet *p_st_cics_packet = NULL;
    p_st_cics_packet = (L7_cics_packet *) frmalloc(sizeof(L7_cics_packet));
    CU_ASSERT_PTR_NOT_NULL(p_st_cics_packet);
    memset(p_st_cics_packet, 0x00, sizeof(L7_cics_packet));

    CU_ASSERT_EQUAL(cics_init_packet(p_st_cics_packet), FR_SUCC);

    CU_ASSERT_PTR_NOT_NULL(p_st_cics_packet->p_st_packet);
    CU_ASSERT_EQUAL(p_st_cics_packet->ui_length, 0);
    CU_ASSERT_EQUAL(p_st_cics_packet->ui_header_len, 0);
    CU_ASSERT_EQUAL(p_st_cics_packet->ui_len_to_read, 0);
    CU_ASSERT_EQUAL(p_st_cics_packet->fragment_state, APM_CICS_FRAGMENT_INIT);
    CU_ASSERT_EQUAL(p_st_cics_packet->ul_skip_len, 0L);
    CU_ASSERT_EQUAL(p_st_cics_packet->ui_flow_version, 0);
    CU_ASSERT_EQUAL(p_st_cics_packet->ui_flow_type, 0);
    CU_ASSERT_EQUAL(p_st_cics_packet->em_req_type, APM_CICS_REQTYPE_UNKNOWN);

    __cics_destroy_packet(&p_st_cics_packet);
    CU_ASSERT_PTR_NULL(p_st_cics_packet);
}

int add_suite_cics_init_packet(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite(MODULE_NAME" cics_init_packet()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    if (CU_add_test(pSuite, "case1", __case1) == NULL)
        return FR_FAIL;

    return FR_SUCC;
}
